x
import numpy as npimport pandas as pdpd.read_csv("diamonds.csv")xxxxxxxxxxdata = pd.read_csv("diamonds.csv")print(data.head())xxxxxxxxxximport pandas as pdimport numpy as npimport plotly.express as pximport plotly.graph_objects as goxxxxxxxxxx# Now let’s start analyzing diamond prices. I will first analyze the relationship between the carat and the price of the diamond to see how the number of carats affects the price of a diamond:xxxxxxxxxxfigure = px.scatter(data_frame = data, x="carat", y="price", size="depth", color= "cut", trendline="ols")figure.show()xxxxxxxxxx# We can see a linear relationship between the number of carats and the price of a diamond. It means higher carats result in higher prices.xxxxxxxxxx# Now I will add a new column to this dataset by calculating the size (length x width x depth) of the diamond:xxxxxxxxxxdata["size"] = data["x"] * data["y"] * data["z"]print(data)xxxxxxxxxx# Now let’s have a look at the relationship between the size of a diamond and its price:figure = px.scatter(data_frame = data, x="size", y="price", size="size", color= "cut", trendline="ols")figure.show()xxxxxxxxxx# Now let’s have a look at the prices of all the types of diamonds based on their colour:xxxxxxxxxxfig = px.box(data, x="cut", y="price", color="color")fig.show()xxxxxxxxxx# Now let’s have a look at the prices of all the types of diamonds based on their clarity:x
fig = px.box(data, x="cut", y="price", color="clarity")fig.show()xxxxxxxxxxType Markdown and LaTeX:
x
fig = px.box(data, x="cut", y="price", color="clarity")fig.show()